import java.util.LinkedHashMap;
import java.util.Map;

public class map {
    public void sortColors(int[] nums) {
        int len = nums.length;
        Map<Integer, Integer> map = new LinkedHashMap<>();
        for (int i = 0; i < len; i++) {
            map.put(nums[i], map.getOrDefault(nums[i], 0) + 1);
        }
        int count0 = map.get(0);
        int count1 = map.get(1);
        int count2 = map.get(2);
        int count = 0;
        while (count0 != 0) {
            count0--;
            nums[count++] = 0;
        }
        while (count1 != 0) {
            count1--;
            nums[count++] = 1;
        }
        while (count2 != 0) {
            count2--;
            nums[count++] = 2;
        }

    }
}
